import {Message} from 'element-ui'

export function imageRatio(raw,type) {
  return new Promise((resolve, reject) => {
    let reader = new FileReader()
    reader.readAsDataURL(raw)
    reader.onload = () => {
      let img = new Image()
      img.src = reader.result
      img.onload = () => {
        //   console.log(img.naturalWidth / img.naturalHeight)
        if(type) {
          if (img.naturalWidth / img.naturalHeight !== 4/3) {
              Message.error(`请上传4:3比例图片!`)
              resolve(false)
          } else {
              resolve(true)
          }
        }else {
          if (img.naturalWidth / img.naturalHeight !== 1) {
              Message.error(`请上传1:1比例图片!`)
              resolve(false)
          } else {
              resolve(true)
          }
        }
      }
    }
  })
}
